#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/7/19  17:32
# @Author: 余浪人
# @email: yulangren520@gmail.com

from apps.models import db, BaseModel
from apps.lib.public import random_click


class TL_Column_model(BaseModel):
    column_name = db.Column(db.String(64))
    column_link = db.Column(db.String(1024))
    column_keyword = db.Column(db.String(1024))
    column_description = db.Column(db.String(1024))
    column_order = db.Column(db.Integer, default=0)
    column_parent_id = db.Column(db.Integer, default=0)

    def __repr__(self):
        return f'分类:<{self.column_name}>'

    def keys(self):
        return 'column_name', 'column_link', 'column_keyword', 'column_description', 'column_parent_id', 'column_order'


class TL_Content_Model(BaseModel):
    title = db.Column(db.String(255))
    title_color = db.Column(db.String(10))
    superior = db.Column(db.Integer, db.ForeignKey(TL_Column_model.id))
    content = db.Column(db.Text)
    pay_content = db.Column(db.Text)
    permissions = db.Column(db.Integer, default=0)
    reward = db.Column(db.FLOAT)
    download = db.Column(db.Text)
    thumb_img = db.Column(db.Text)
    clicks = db.Column(db.Integer, default=random_click)
    author = db.Column(db.String(64), default='佚名',)
    keyword = db.Column(db.String(512))
    description = db.Column(db.String(512))
    contributor = db.Column(db.String(64))
    is_focus = db.Column(db.Boolean, default=0)
    is_roll = db.Column(db.Boolean, default=0)
    is_roll_text = db.Column(db.Boolean, default=0)
    is_index_stick = db.Column(db.Boolean, default=0)
    is_list_stick = db.Column(db.Boolean, default=0)
    is_recommend = db.Column(db.Boolean, default=0)
    pro = db.relationship('TL_Column_model', backref='content_model')

    def __repr__(self):
        return f'内容标题: <{self.title}>'

    def keys(self):
        return 'title', 'title_color', 'superior', 'content', 'pay_content', 'permissions', 'reward', 'download', 'thumb_img', 'clicks', 'author', 'keyword', 'description', 'contributor', 'is_focus', 'is_roll', 'is_roll_text', 'is_index_stick', 'is_list_stick', 'is_recommend', 'update_time', 'uuid'


class TL_Comment_Model(BaseModel):
    content_uuid = db.Column(db.String(16), db.ForeignKey(TL_Content_Model.uuid))
    comment_txt = db.Column(db.Text)
    user_qq = db.Column(db.String(12))
    user_name = db.Column(db.String(32))
    pro = db.relationship('TL_Content_Model', backref='comment_model')

    def __repr__(self):
        return f'评论用户: <{self.user_name}>'

    def keys(self):
        return 'content_uuid', 'comment_txt', 'user_qq', 'user_name', 'update_time', 'status'


class TL_Tags_Model(BaseModel):
    tag_name = db.Column(db.String(255),unique=True)
    tag_click = db.Column(db.Integer, default=0)

    def __repr__(self):
        return f'标签名: <{self.tag_name}>'

    def keys(self):
        return 'tag_name', 'tag_click'
